<template lang=pug>




</template>

<script type="es6">
    import BScroll from 'better-scroll'
    import _ from 'underscore'
    import vSimpleRent from './simpleRent.vue'
    export default {
        name: 'body',
        mounted (){
            var self = this
            console.log(this)
            this.$http.get('/order/get',{
                params:{
                    pageSize:10,
                    pageNumber:self._data.pageNumber,
                    key:this.$store.state.rentSearchKey
                }
            }).then(response=>{
                this.$store.commit('updateRentList',response.data.data.list)
                console.log('RentList=',response.data.data.list)
            }).catch(error=> {
                console.log(error)
            })

            console.log(this.$refs.rentList)
            let scroll = new BScroll(this.$refs.rentList, {
                startX: 0,
                startY: 0,
                click: true,
                probeType: 3
            })
            console.log(scroll)
            scroll.on('scroll', (pos) => {
//                console.log(pos)
//                console.log(pos.x + '~' + pos.y)
                if (pos.y<=-672&&self.state=='normal'){
                    self.nextPage()
                }
                if (pos.y>=100&&self.fleshState=='canReflesh'){
                    console.log('reflesh')
                    self.reflesh()
                }
            })
//            this.$http.axios.post('/user', {
//                firstName: 'Fred',
//                lastName: 'Flintstone'
//            })
//            function getUserAccount() {
//                return axios.get('/user/12345');
//            }
//
//            function getUserPermissions() {
//                return axios.get('/user/12345/permissions');
//            }
//
//            axios.all([getUserAccount(), getUserPermissions()])
//                .then(axios.spread(function (acct, perms) {
//                    // Both requests are now complete
//                }));
        },
        data () {
            return {
                pageNumber:1,
                state:'normal',
                fleshState:'canReflesh'
            }
        },
        methods:{

            nextPageDebounce(){
                let self = this
                return _.debounce(self.nextPage(),3000)
            },
            nextPage(){

                let self = this
                self.state='sending'
                this._data.pageNumber++
                console.log(this._data.pageNumber)

                this.$http.get('/order/get',{
                    params:{
                        pageSize:10,
                        pageNumber:this._data.pageNumber,
                        key:this.$store.state.rentSearchKey
                    }
                }).then(response=>{
                    this.$store.commit('updateNextPageRentList',response.data.data.list)
                    setTimeout(()=>{self.state='normal'},1000)
                })
            },
            reflesh (){
                this.pageNumber =1
                let self= this
                self._data.fleshState='canNotReflesh'
                this.$http.get('/order/get',{
                    params:{
                        pageSize:10,
                        pageNumber:self._data.pageNumber,
                        key:this.$store.state.rentSearchKey
                    }
                }).then((response)=>{
                    console.log(response.data.data.list.length)
                    this.$store.commit('updateRentList',response.data.data.list)
                    setTimeout(()=>{self._data.fleshState = 'canReflesh'},1000)
                })
            }
        },
        components: {
            vSimpleRent
        }
    }
</script>

<style lang="stylus" scoped>
    div
        height 100%
        ul
            position absolute
            top 0rem
            bottom  0rem

</style>
